package cn.flant.io;

import java.net.Socket;
import java.util.Scanner;

import cn.flant.io.tcp.MessageHandler;
import cn.flant.io.tcp.ObjectMessageHandler;
import cn.flant.io.tcp.SocketHandler;
import cn.flant.io.tcp.TcpServer;

public class MyHandler extends SocketHandler {

	public MyHandler(Socket socket, TcpServer server) throws Exception {
		super(socket, server);
	}

	@Override
	public MessageHandler createMessageHandler() {
		return new ObjectMessageHandler();
	}

	@Override
	public void processMessage(Object line) {
		System.err.println(line);
	}

	@Override
	public synchronized void startup() {
		super.startup();
		new Thread() {
			public void run() {
				Scanner scanner = new java.util.Scanner(System.in);
				while (MyHandler.this.isRunning()) {
					String line = scanner.nextLine();
					sendMessage(line);
				}
			}
		}.start();
	}
}
